package com.love.poetry.application.security.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.love.poetry.application.security.RoleService;
import com.love.poetry.domain.security.Role;
import com.love.poetry.infrastructure.persist.security.RoleRepository;
import com.youboy.core.domain.event.LifecycleEvent;
import com.youboy.core.domain.event.LifecycleEventHandler;
import com.youboy.core.orm.Page;

@Transactional
@Service
public class RoleServiceImpl extends LifecycleEventHandler implements RoleService {
	
	@Autowired
    private RoleRepository roleRepository ;


    public Role get(String id) {
                return roleRepository .get(id);
   }


    public List<Role> query(Object object) {
                return roleRepository .query(object);
   }


    public Page<Role> queryPage(Page<Role> page) {
                return roleRepository .queryPage(page);
   }


    protected void onModify(Object source, long timestamp) {
               Role entity = (Role) source;
                roleRepository .update(entity);
   }


    protected void onDelete(Object source, long timestamp) {
               Role entity = (Role) source;
                roleRepository .delete(entity);
   }


    protected void onCreate(Object source, long timestamp) {
               Role entity = (Role) source;
                roleRepository .save(entity);

   }


    protected boolean isAcceptableLifecycleEvent(LifecycleEvent event) {
                return Role. class.isAssignableFrom(event.getSource().getClass());
   }


}
